﻿using System;
using System.Linq;
using System.Windows.Forms;

namespace BigEaterCh
{
  public partial class FormWz : FormZywienie
  {

    private static FormWz _instance;

    public static FormWz Pokaz(Form parentForm)
    {
      if (_instance != null)
      {
        _instance.RefreshDB();
      }
      else
      {
        _instance = new FormWz
        {
          MdiParent = parentForm
        };
      }
      return _instance;
    }


    private FormWz()
    {
      InitializeComponent();
      RefreshDB();
    }

    private void RefreshDB()
    {
      FormBigEaterCh.GetDataBase();
      this.wzBindingSource.DataSource = FormBigEaterCh.Ze.Wz;
      this.fakturyBindingSource.DataSource = FormBigEaterCh.Ze.Faktury;
      this.firmyBindingSource.DataSource = FormBigEaterCh.Ze.Firmy;
    }

    private void FormProdukty_FormClosing(object sender, FormClosingEventArgs e)
    {
      Hide();
      e.Cancel = true;
    }

    private void produktyBindingNavigatorSaveItem_Click(object sender, EventArgs e)
    {
      FormBigEaterCh.SaveDataBase();
      FormBigEaterCh.Ze.Refresh(System.Data.Objects.RefreshMode.StoreWins, FormBigEaterCh.Ze.Wz);
    }
  }
}
